
<template>
  <div>
    <Modal
      v-model="posswordSet"
      :title="'修改登录密码'"
      :footer-hide="true"
      :mask-closable="false"
      @on-visible-change="vChange"
      width="500"
    >
      <div class="f_16 marginB20">用户手机：{{mobile}}</div>

      <Row class="marginB20" :gutter="20">
        <Col span="16">
          <Input type="number" placeholder="短信验证码" v-model="code" ref="code" clearable size="large"
          onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
          >
            <Icon type="ios-chatboxes" slot="prefix" />
          </Input>
        </Col>
        <Col span="8">
        <!-- button 倒计时函数，要用jq处理，原因细说 -->
          <Button
            type="primary"
            size="large"
            long
            @click="goCodeFun"
            :disabled="btnDisabled"
            id="fDom"
          >获取验证码</Button>
        </Col>
      </Row>

      <Input type="password" v-model="password" placeholder="请输入 不低于6位数密码" ref="password" class="marginB20" size="large" clearable>
        <Icon type="md-lock" slot="prefix" />
      </Input>
      <Input type="password" v-model="passwordAG" placeholder="再次确认密码" ref="passwordAG" class="marginB20" size="large" clearable>
        <Icon type="md-lock" slot="prefix" />
      </Input>

      <Button type="primary" class="marginB10" size="large" long @click="goFun">确 定</Button>
    </Modal>
  </div>
</template>



<script>
export default {
  name: "posswordSet",
  components: {},
  data() {
    let data = {
      // 弹框是否显示
      posswordSet:false,
      mobile: '',
      phoneOk:true,//true该手机 已注册存在系统

      password: "",
      passwordAG:'',
      captcha: "", //图形 验证码
      code: "", //手机 验证码

      // 获取验证码按钮
      btnDisabled: false
    };
    return data;
  },
  props:['userPower','companyAll'],
  watch:{
    userPower(newVal,oldVal){

      this.mobile=newVal.mobile;

    },
    companyAll(newVal,oldVal){
      this.companyAll=newVal;
    },
  },
  created() {
  },
  methods: {
    goCodeFun() {

      let that=this;
      let {
        mobile
      }=this;
      //2登录,3修改密码,4合伙人认证,5绑定邮箱
      $ajax.getCodeNn(that,'fDom',mobile,3);
    },
    //提交
    goFun() {
      let that=this;
      let {mobile,password,passwordAG,code}=that;
      
      if(!$app.judgeData(code)){
        that.$Message.error({content:'验证码不能为空'});
        that.$refs['code'].focus();
      }else if(!$app.judgeData(password)){
        that.$Message.error({content:'密码不能为空'});
        that.$refs['password'].focus();
      }else if(password.length<6){
        that.$Message.error({content:'密码不能小于6位数'});
        that.$refs['password'].focus();
      }else if(passwordAG!=password){
        that.$Message.error({content:'请再次确认密码'});
        that.$refs['passwordAG'].focus();
      }else{
        // 修改密码成功，会强制性退出，重新登录
        $ajax.updatePwd(2,mobile,password,code,that);
      }
    },
    //弹框消失
    vChange(buEr) {
      if(!buEr){//关闭
        // 清空数据
        this.password= "";
        this.passwordAG="";
        this.captcha= ""; //图形 验证码
        this.code= ""; //手机 验证码
      }
    }
  }
};
</script>
